﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace SLBehaviourSystem
{
    [ConditionNode]
    public  class ConditionNode : BehaviourNodeBase, IConditionNode
    {
        public virtual BehaviourNodeState CheckCondition()
        {
            return BehaviourNodeState.Failure;
        }

        public override BehaviourNodeState Excute()
        {
            base.Excute();
            Component.BindNode(this);
            curNodeState = Component.Excute();
            if (curNodeState == BehaviourNodeState.Success || curNodeState == BehaviourNodeState.Failure)
            {
                if (parent != null)
                {
                    parent.ChildNodeComplete();
                }
            }
            return curNodeState;
        }

        public void CheckInterrupt()
        {
            if (parent != null)
            {
                CompositeNode compositeNode = parent as CompositeNode;
                if (compositeNode != null)
                {
                    compositeNode.CheckInterrupt(this);
                }
            }
        }
    }
}